package jp.tonosama.komoki.SimpleGolfScorer2.data;

import java.io.Serializable;
import java.util.Comparator;

/**
 * @author Komoki
 */
public class SaveDataComparator implements Comparator<Object>, Serializable {

    /**  */
    private int mCompare;

    public SaveDataComparator() {
        mCompare = 0;
    }

    /**
     * @param sortType sortType
     */
    public SaveDataComparator(final int sortType) {
        if (sortType == 0) {
            mCompare = 0;
        } else if (sortType == 1) {
            mCompare = 1;
        } else if (sortType == 2) {
            mCompare = -1;
        }
    }

    /* (non-Javadoc)
     * @see java.util.Comparator#compare(T, T)
     */
    public int compare(final Object arg0, final Object arg1) {
        SaveData data0 = (SaveData) arg0;
        SaveData data1 = (SaveData) arg1;
        if (data0.getTitle().compareToIgnoreCase(data1.getTitle()) < 0) {
            return 1 * mCompare;
        } else if (data0.getTitle().compareToIgnoreCase(data1.getTitle()) == 0) {
            return 0;
        } else {
            return -1 * mCompare;
        }
    }
}
